package com.qidian.md.service.impl;

import com.qidian.md.mapper.WorkstationMapper;
import com.qidian.md.service.WorkstationService;
import com.qidian.mes.pojo.md.Workstation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qidian.mes.util.pojo.MESResult;
import com.qidian.mes.util.pojo.Pager;
/**
 * @Author 18林梦雅
 * @Company 起点编程
 * @Time 2023/10/31 19:43
 * @Description
 */
@Service
public class WorkstationServiceImpl implements WorkstationService {
    @Autowired
    WorkstationMapper workstationMapper;

    @Override
    public MESResult queryByPage(Workstation workstation, int page, int limit) {
        Pager<Workstation> pager=new Pager<>();
        pager.setCurr(page);
        pager.setLimit(limit);
        pager.setTotal( workstationMapper.selectCount(workstation));
        pager.setData(workstationMapper.selectByPage(workstation,(page-1)*limit,limit));
        pager.setMaxPageNum((int) Math.ceil(pager.getTotal()*1.0/limit));
        return MESResult.ok(pager);

    }


    /**
     * 添加工作站,先判断工作站名是否重复,再添加
     * @param workstation
     * @return
     */
    @Override
    public MESResult addWorkstation(Workstation workstation) {

        return MESResult.updateIsOk(workstationMapper.addWorkstation(workstation));
    }



    /**
     * 先根据Id查询内容,返回给前端的编辑页面
     * @param workstationId
     * @return
     */
    @Override
    public MESResult queryById(Long workstationId) {
        Workstation workstation = null;
        if ((workstation = workstationMapper.selectById(workstationId)) != null){
            return MESResult.ok(workstation);
        }
        return MESResult.empty();
    }



    /**
     * 根据工作站id-->工作站修改编辑
     * 直接更新数据,不用判断工作站名是否重复,编码是不一样的
     * @param workstation
     * @return
     */

    @Override
    public MESResult update(Workstation workstation) {

        return MESResult.updateIsOk(workstationMapper.update(workstation));

    }




    /**
     * 单行删除功能
     * @param workstationId
     * @return
     */
    @Override
    public MESResult deleteUpdateStatus(Long workstationId) {
        return MESResult.ok(workstationMapper.deleteUpdateStatus(workstationId));
    }






    /**
     * 选中多行删除功能
     * @param workstationId
     * @return
     */
    @Override
    public MESResult deleteUpdateSelect(Long[] workstationId) {
        int count=workstationMapper.deleteUpdateSelect(workstationId);
        return MESResult.ok(count+" ");
    }



}


